import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Ladron here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Ladron extends Enemigos
{
    private int Salud ;
    private int Speed;
    private int animationCounter;
    private final int NUM_IMAG = 4;
    private Ninja ninja;
    private boolean isDead;   
    private GreenfootSound DagaEncajada;
    private final GreenfootImage[] RunLeft = new GreenfootImage[NUM_IMAG];//Arreglo de imagenes correr hacia la derecha
    
    private Cuchillo cuchillo;
    
    
    public Ladron (){
       Salud = 100; 
       Speed = 3;
       animationCounter = 0;
       isDead = false;
       
       for(int i = 0; i<NUM_IMAG; i++){
          RunLeft[i] = new GreenfootImage("ladronC"+i+".png");
           }
         
          DagaEncajada = new GreenfootSound("DagaEncajada.wav");   
    }
    
    /**
     * Act - do whatever the Ladron wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        /*Niveles mundo = (Niveles)this.getWorld();
        ninja = mundo.ninja;
        Object obj = getObjectsInRange( 20 ,null);
        if(obj == ninja)
        */
       if(!isDead){
         mueveLeft();
         checaLimite();
        }
        
       checaColision(); 
        
    }  
    
    /**
     * Mueve Ladron hacia la Izquierda 
     */
    public void mueveLeft(){
        
        setLocation (this.getX() - Speed, this.getY());
        animationCounter ++;    
        if(animationCounter < 4)
            setImage(RunLeft[0]);
        else if(animationCounter < 8)
            setImage(RunLeft[1]);
        else if(animationCounter < 12)
            setImage(RunLeft[2]);
        else if(animationCounter < 16)
            setImage(RunLeft[3]);
        else if(animationCounter == 16 )
                animationCounter = 0;
    
       }
       
    public void checaLimite(){
    
    if(getX() < -200) 
     setLocation (getWorld().getWidth(), this.getY());
    }   
       
    public void checaColision(){
       
        Niveles mundo = (Niveles)this.getWorld();
        ninja = mundo.ninja;
       
        if(isTouching(Daga.class)){
             DagaEncajada.play();
             removeTouching(Daga.class);
             setLocation (this.getX() + 20, this.getY());
             Salud -= 50;
        
                    
        }
        
        if(isTouching(Onda.class)){
            DagaEncajada.play();
            removeTouching(Onda.class);
            setLocation (this.getX() + 20, this.getY());
            Salud -= 50;
                          
        }
        
         if(Salud <= 0){
              ninja.aumentaPuntos(10);
              cuchillo = new Cuchillo();
              mundo.addObject(cuchillo, this.getX(), this.getY()+10);
              getWorld().removeObject(this);
              isDead = true; 
           }
    
       }

}
